home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / et / et3_0-a1.lha / et3 / src / PROGENV / DefObjectViews.C < prev    next >
C/C++ Source or Header  |  1992-05-14  |  4KB  |  143 lines

  1. #ifdef __GNUG__
  2. #pragma implementation
  3. #endif
  4.  
  5. #include "Class.h"
  6. #include "ProgEnv.h"
  7. #include "Window.h"
  8. #include "Scroller.h"
  9. #include "ImageItem.h"
  10. #include "String.h"
  11.  
  12. #include "CollTblView.h"
  13. #include "Collection.h"
  14.  
  15. #include "Dictionary.h"
  16. #include "OrdColl.h"
  17.  
  18. class PeDefaultViews: public ObjectViewPolicy {
  19.     Window *collWindow, *dictWindow, *bitmapWindow;
  20.     PeCollTableView *collView;
  21.     PeDictionaryView *dictView;
  22.     ImageItem *bitmap;
  23. public:
  24.     MetaDef(PeDefaultViews);
  25.     PeDefaultViews();
  26.     ~PeDefaultViews();
  27.     char *ViewName(Class *cl, void *addr, Object *op);
  28.     bool ShowView(Class *cl, void *addr, Object *op, Object *);
  29.     void ShowVObjectTree(VObject*);
  30.     void ShowDictionaryView(Dictionary*);
  31.     void ShowCollectionView(Collection*);   
  32.     void ShowBitmap(Bitmap *bm);
  33. };
  34.  
  35. NewMetaImpl(PeDefaultViews, ObjectViewPolicy, (TP(collWindow), TP(dictWindow), TP(bitmapWindow),
  36.                     TP(collView), TP(dictView), TP(bitmap)));
  37.  
  38. PeDefaultViews::PeDefaultViews()
  39. {
  40.     collWindow= dictWindow= bitmapWindow =0;
  41.     bitmap= new ImageItem(new Bitmap(gPoint1, 1), 0, TRUE);
  42. }
  43.  
  44. PeDefaultViews::~PeDefaultViews()
  45. {
  46.     SafeDelete(bitmap);
  47. }
  48.  
  49. char *PeDefaultViews::ViewName(Class *cl, void *, Object *op)
  50. {
  51.     if (!op)
  52.     return 0;
  53.     if (op->IsKindOf(ImageItem)) 
  54.     return "Bitmap View";
  55.     if (op->IsKindOf(VObject)) 
  56.     return "VObject-Tree View";
  57.     if (op->IsKindOf(Dictionary) && ((Dictionary*)op)->Size()) 
  58.     return "Dictionary View";
  59.     if (op->IsKindOf(Collection) && ((Collection*)op)->Size()) 
  60.     return "Collection View";
  61.     if (cl && strcmp(cl->Name(), "Bitmap") == 0)
  62.     return "Bitmap View";
  63.     return 0;
  64. }
  65.  
  66. bool PeDefaultViews::ShowView(Class *cl, void *addr, Object *op, Object *)
  67. {
  68.     if (op->IsKindOf(ImageItem)) {
  69.     ImageItem *im= (ImageItem*)addr;
  70.     if (im->GetBitmap()) {
  71.         ShowBitmap(im->GetBitmap());
  72.         return TRUE;
  73.     }
  74.     }
  75.     if (op->IsKindOf(VObject)) {
  76.     ShowVObjectTree((VObject*)op);
  77.     return TRUE;
  78.     }
  79.     if (op->IsKindOf(Dictionary)) {
  80.     ShowDictionaryView((Dictionary*)op);
  81.     return TRUE;
  82.     } 
  83.     if (op->IsKindOf(Collection)) {
  84.     ShowCollectionView((Collection*)op); 
  85.     return TRUE;
  86.     } else if (cl && strcmp(cl->Name(), "Bitmap") == 0) {
  87.     ShowBitmap((Bitmap*)addr);
  88.     return TRUE;
  89.     }
  90.     return FALSE;  
  91. }
  92.  
  93. void PeDefaultViews::ShowVObjectTree(VObject*vop)
  94. {
  95.     VObject *root= 0;
  96.     while (vop) {
  97.     root= vop;
  98.     vop= vop->GetContainer();
  99.     }
  100.     if (root)
  101.     gProgEnv->ShowInObjStruBrowser(root);            
  102. }
  103.  
  104. void PeDefaultViews::ShowCollectionView(Collection* col)
  105. {
  106.     if (collWindow == 0) {
  107.     collView= new PeCollTableView();        
  108.     collWindow= new Window(0, Point(300, 100), eWinCanClose, new Scroller(collView));
  109.     }
  110.     collWindow->SetTitle(form("Collection: 0x%x (%s)", (int)col, col->ClassName()));
  111.     collWindow->OpenAt(Point(800,500));
  112.     collView->ShowCollection(col);
  113. }
  114.    
  115. void PeDefaultViews::ShowDictionaryView(Dictionary* col)
  116. {
  117.     if (dictWindow == 0) { 
  118.     dictView= new PeDictionaryView();        
  119.     dictWindow= new Window(0, Point(600, 100), eWinCanClose, new Scroller(dictView));
  120.     } 
  121.     dictWindow->SetTitle(form("Dictionary: 0x%x (%s)", (int)col, col->ClassName()));
  122.     dictWindow->OpenAt(Point(800,500));
  123.     dictView->ShowDictionary(col);
  124. }
  125.    
  126. void PeDefaultViews::ShowBitmap(Bitmap *bm)
  127. {
  128.     Bitmap *bm2= (Bitmap*)bm->DeepClone();
  129.     if (bitmapWindow == 0)
  130.     bitmapWindow= new Window(0, Point(250, 200), eWinCanClose, new Scroller(bitmap));
  131.     bitmapWindow->SetTitle(form("Bitmap: w: %d h: %d d: %d", 
  132.                 bm2->Size().x, bm2->Size().y, bm2->GetDepth()));
  133.     bitmapWindow->OpenAt(Point(800,500));
  134.     bitmap->SetBitmap(bm2);
  135.     bitmapWindow->UpdateEvent();
  136. }
  137.  
  138. void ObjectViewOnEntry(ProgEnv *pe)
  139. {
  140.     pe->AddObjectViewPolicy(new PeDefaultViews);
  141. }
  142.  
  143.